import Vue from "vue";
import VueJsonp from "vue-jsonp";

Vue.use(VueJsonp);

const URLS={
    HomeUrl:"https://mce.mogucdn.com/jsonp/multiget/3",
    HomeYourLike:"https://list.mogujie.com/search",
    ClassifyRightType:"https://mce.mogucdn.com/jsonp/get/3",
    SearchWord:"https://list.mogujie.com/module/mget",
    DetailProduct:"https://rate.mogujie.com/h5/rate/jsonp/x6.rate.ratelist/v1"
};

const showError=function(error){
    // console.log(error,error.message);
    if(error.message){
        window.showMsgBox(error.message,true);
    }else{
        window.showMsgBox(error,true);
    };
};

const loadImgForHome=function(params){
    return Vue.jsonp(URLS.HomeUrl,params);
};
const loadThinkYourLike=function(params){
    return Vue.jsonp(URLS.HomeYourLike,params);
};
const loadClassifyType=function(params){
    return Vue.jsonp(URLS.ClassifyRightType,params);
};
const loadSearchWord=function(params){
    return Vue.jsonp(URLS.SearchWord,params);
};
const loadDetailProduct=function(params){
    return Vue.jsonp(URLS.DetailProduct,params);
};


export default {
    install(Vue){//用于在组件中使用
        Vue.prototype.$api={
            loadImgForHome,
            loadThinkYourLike,
            loadClassifyType,
            loadSearchWord,
            loadDetailProduct
        };
        window.showError=Vue.prototype.$error=showError;
    },
    //用于在vuex中actions使用
    showError,
    loadImgForHome,
    loadThinkYourLike,
    loadClassifyType,
    loadSearchWord,
    loadDetailProduct
}